//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <unistd.h>

#include <iostream>

#include "ModelsReports.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define MESSAGE 1
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  String*        folderReportsOut = NULL;
  String*        headerModel      = NULL;
  
  if (argc < 4) {
    
    if (MESSAGE) {
      cout << "Error in the input parameters! Must by like: " << endl;
      cout << "./DesignReportsOfModelsByLigand  <Folder Out>";
      cout <<                                 " <Header Model Evaluation (training-data, cross-validation, test-data)>";
      cout <<                                 " <Filename with Models (XML)>";
      cout <<                                 " [Filename with Models (XML)] ...";
      cout << endl;
    }
    
    return EXIT_FAILURE;
    
  }
  else {
    
    folderReportsOut = new String(argv[1]);
    headerModel      = new String(argv[2]);
    
    if (MESSAGE) {
      cout << "-----------------------------------------------------------------------------------" << endl;
      cout << "                  Folder Out : " << argv[1] << endl;
      cout << "     Header Model Evaluation : " << argv[2] << endl;    
      for (int i = 3; i < argc; i++)
        if (access(argv[i], F_OK) != -1) 
          cout << "  Filename with Models (XML) : " << argv[i] << endl;    
      cout << "-----------------------------------------------------------------------------------" << endl;
    }
    
  }

  ModelsReports* modelsReports = new ModelsReports ();

  cout << "Preparing the files..." << endl;
  for (int i = 3; i < argc; i++)
    if (access(argv[i], F_OK) != -1) 
      modelsReports->ListFilenameIn()->Add(new String(argv[i]));
  modelsReports->FolderReportsOut(folderReportsOut);
  
  cout << "Loading models in memory..." << endl;
  if (!modelsReports->LoadXMLFiles())
    cout << "Error loading models in memory!" << endl;
  
  cout << "Creating reports..." << endl;
  if (!modelsReports->CSVReportsByLigand(headerModel))
    cout << "Error creating a csv reports!" << endl;
  if (!modelsReports->LatexReportsByLigand(headerModel))
    cout << "Error creating a latex reports!" << endl;
  
  cout << "Finished..." << endl << "Good Bye" << endl;
  cout << "-----------------------------------------------------------------------------------" << endl;
  
  if (modelsReports)     delete modelsReports;
  
  if (folderReportsOut)  delete folderReportsOut;
  if (headerModel)       delete headerModel;

  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

